package com.example.service.webhook.business.court.repository;

import com.example.service.webhook.business.court.entity.ZhixingCourtCaseDetailEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by zouwanli on 17/5/31.
 */
@Repository
public class ZhixingCourtCaseDetailRepository extends BaseDAO<ZhixingCourtCaseDetailEntity> {

    @Resource(name="templateCourt")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void saveZhixingCourtCaseDetail(ZhixingCourtCaseDetailEntity entity) throws Exception  {
        entity.setCreateTime(DateUtil.getCurrentDate());
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.add(entity);
    }

    public void updateZhixingCourtCaseDetail(ZhixingCourtCaseDetailEntity entity) throws Exception  {
        entity.setLastModifyTime(DateUtil.getCurrentDate());
        this.modify(entity);
    }


    public ZhixingCourtCaseDetailEntity getZhixingCourtCaseDetail(String userId, String mappingId, String caseId) throws Exception {
        String sql = "";
        String tableName = "t_zhixingcourtcasedetail";
        sql = "select * from " + tableName + " where mappingId=? and caseId=? and userId=?";
        ZhixingCourtCaseDetailEntity pojo = null;
        try{
            pojo = (ZhixingCourtCaseDetailEntity) queryOne(sql, new Object[] {mappingId, caseId, userId}, new ZhixingCourtCaseDetailEntity());
        }catch(EmptyResultDataAccessException e){
            return null;
        }

        return pojo;
    }
}
